package net.dgg.zz.production.nodeOverdue.service;


import com.alibaba.fastjson.JSONObject;
import net.dgg.framework.tac.utils.idutil.DggKeyWorker;
import net.dgg.iboss.base.service.CmsService;
import net.dgg.iboss.base.util.CustomerNumberEncryptionUtil;
import net.dgg.iboss.base.util.DesUtil;
import net.dgg.iboss.base.util.JsonUtil;
import net.dgg.iboss.base.util.datatable.domain.DataTableRequest;
import net.dgg.iboss.base.util.datatable.domain.DataTableResponse;
import net.dgg.iboss.base.util.http.HttpUtility;
import net.dgg.tmd.foundation.platform.common.service.BaseService;
import net.dgg.tmd.foundation.platform.org.service.OrganizationManager;
import net.dgg.tmd.foundation.platform.user.entity.UserEntity;
import net.dgg.tmd.foundation.platform.user.service.UserService;
import net.dgg.zz.common.constant.CmsNodeConstant;
import net.dgg.zz.common.dto.TimeoutPunishDto;
import net.dgg.zz.common.excption.CommonExcption;
import net.dgg.zz.common.utils.RegularUtil;
import net.dgg.zz.common.utils.StringUtils;
import net.dgg.zz.production.entity.ProductOrder;
import net.dgg.zz.production.nodeOverdue.dto.AddDeductionAppealDto;
import net.dgg.zz.production.nodeOverdue.dto.DeductionAppealDto;
import net.dgg.zz.production.nodeOverdue.dto.UpdateDeductionAppealDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.util.Assert;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;

@Service
public class FlscNodeOverdueServiceImpl extends BaseService implements FlscNodeOverdueService {

    @Autowired
    private DesUtil desUtil;//解密加密
    @Autowired
    private UserService userService;//用户
    @Value("${scCmsUrl}")
    private String cmsNodeUrl;    //cms节点管理网址
    //@Autowired
    //private FlscProductOrderService productOrderService;//生产订单相关
    @Autowired
    private OrganizationManager organizationManager;//部门
    @Autowired
    private CmsService cmsService;
    @Autowired
    private ProductOrderService productOrderService;
    private final Logger logger = LoggerFactory.getLogger(FlscNodeOverdueServiceImpl.class);


    /**
     * 到cms公共节点管理中，查询超期节点记录
     *
     * @param params
     * @param user
     * @return
     */
    @Override
    public JSONObject selectNodeOverdueRecord(Map<String, Object> params, UserEntity user) throws IOException {

        try {
            //查询当前部门及以下
            List<Long> orgIds = organizationManager.findOrgIdByAncestorId(user.getOrgId());
            params.put("orgIds", orgIds);
            //二级业态code
            //params.put("businessCode", "BUS_YT_ZZ");

            String bas = HttpUtility.postJson(cmsNodeUrl + CmsNodeConstant.QUERY_TIMEOUT_PUNISH, params);
            if (StringUtils.isEmpty(bas)) {
                throw new CommonExcption("查询节点扣罚记录失败，请联系管理员");
            }

            //获取查询结果
            JSONObject jsonObject = JSONObject.parseObject(bas);
            if (!"0".equals(jsonObject.getString("code"))) {
                throw new CommonExcption("查询节点扣罚记录失败，请联系管理员");
            }
            JSONObject data = (JSONObject) jsonObject.get("data");
            return data;
        } catch (CommonExcption e) {
            throw new CommonExcption(e.getMessage());
        } catch (Exception e) {
            throw new CommonExcption("查询节点扣罚记录失败，请联系管理员");
        }
    }

    /**
     * 根据id查询超期节点记录
     *
     * @param id 超期节点id
     * @return
     */
    @Override
    public TimeoutPunishDto queryTimeoutPunishById(Long id) throws IOException {

        try {
            String bas = HttpUtility.getRest(cmsNodeUrl + CmsNodeConstant.QUERY_TIME_OUT_PUNISH_BY_ID + "?id=" + id, null);
            if (StringUtils.isEmpty(bas)) {
                throw new CommonExcption("查询节点扣罚记录失败，请联系管理员");
            }
            //获取单条扣罚记录
            JSONObject jsonObject = JSONObject.parseObject(bas);
            if (!"0".equals(jsonObject.getString("code"))) {
                throw new CommonExcption("查询节点扣罚记录失败，请联系管理员");
            }
            if("[]".equals(jsonObject.getString("data"))){
                throw new CommonExcption("未查询到对应节点扣罚记录，请刷新页面");
            }
            TimeoutPunishDto data = JsonUtil.json2Obj(jsonObject.getString("data"), TimeoutPunishDto.class);
            return data;
        } catch (CommonExcption e) {
            throw new CommonExcption(e.getMessage());
        } catch (Exception e) {
            throw new CommonExcption("查询节点扣罚记录失败，请联系管理员");
        }

    }

    /**
     * 提交扣罚申诉
     *
     * @param map  页面传递信息
     * @param user 当前登录用户
     */
    @Override
    @Transactional
    public void deductionAppeal(Map<String, Object> map, UserEntity user) throws IOException {

        //根据id查询审核人
        UserEntity flowUser = userService.findUserById(Long.valueOf(map.get("deductionAppealReviewId").toString()));
        Assert.notNull(flowUser, "未查询到审核人员，请刷新页面");

        //根据扣罚记录id和申诉记录id，查询申诉记录，如果为空，表示第一次进行申诉，
        //查询申诉记录
        List<DeductionAppealDto> appealRecord = getAppealRecord(Long.valueOf(map.get("id").toString()));
        DeductionAppealDto appealByPunishId = getAppealById(appealRecord, Long.valueOf(map.get("appealId").toString()));
        //申诉id不为空，直接进行修改
        if(appealByPunishId !=null){
            continueAppeal(appealByPunishId, map.get("remark").toString(), flowUser, user);
            //创建新的扣罚申诉
        }else {


//            FlscProductOrder flscProductOrder = productOrderService.selectOrderByOrderNo(map.get("orderNo").toString());
            TimeoutPunishDto timeout = queryTimeoutPunishById(Long.parseLong(map.get("id").toString()));
            if (!user.getId().equals(timeout.getFlowUserId())) {
                throw new CommonExcption("当前登录用户，不是扣罚记录对应流程人员");
            }

            //扣罚记录状态后台修改为扣罚中

            //创建申诉记录

            AddDeductionAppealDto appeal = new AddDeductionAppealDto();
            List<ProductOrder> productOrderList = productOrderService.getProductOrder(map);
            if (productOrderList.size()> 0) {
                ProductOrder productOrder = productOrderList.get(0);
                appeal.setContractNo(productOrder.getContractNo());//合同编号\
                appeal.setCustomerId(productOrder.getCustomerId());//客户ID
                appeal.setCustomerNo(productOrder.getCustomerNo());//客户编号
                appeal.setCustomerPhone(productOrder.getCustomerPhone());//客户号码(已加密)
                appeal.setCustomerName(productOrder.getCustomerName());//客户名字
                appeal.setAppealBusinessCode(productOrder.getBusinessProductCode());//申诉业务编码 二级业态
                appeal.setAppealBusinessName(productOrder.getBusinessProductName());//申诉业务名字  二级业态
            }else{
                appeal.setCustomerId(timeout.getCustomerId());//客户ID
                appeal.setCustomerNo(timeout.getCustomerNo());//客户编号
                appeal.setCustomerPhone(timeout.getCustomerPhone());//客户号码(已加密)
                appeal.setCustomerName(timeout.getCustomerName());//客户名字
                appeal.setAppealBusinessCode(timeout.getBusinessCode());//申诉业务编码 二级业态
                appeal.setAppealBusinessName(timeout.getBusinessName());//申诉业务名字  二级业态
                appeal.setWorkOrderNo(timeout.getWorkOrderNo());
            }
            appeal.setId(Long.valueOf(map.get("appealId").toString()));//申诉id
            appeal.setTimeoutPunishId(Long.parseLong(map.get("id").toString()));//扣罚记录id
            appeal.setAppealReason(map.get("remark").toString());//申诉原因
            appeal.setReviewerId(flowUser.getId());//审核人Id
            appeal.setReviewerName(flowUser.getRealName());//审核人名字
            appeal.setUserEntity(JSONObject.toJSONString(user));//当前登录用户

            //保存扣罚申诉记录
           saveDeductionAppeal(appeal);
        }

    }

    /**
     * 保存扣罚申诉记录
     *
     * @param appeal 新增申诉记录对象
     */
    public void saveDeductionAppeal(AddDeductionAppealDto appeal) throws IOException {

        //进行保存
        JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(appeal));
        String bas = HttpUtility.postJson(cmsNodeUrl + CmsNodeConstant.SAVE_DEDUCTION_APPEAL, jsonObject);
        if (StringUtils.isEmpty(bas)) {
            throw new CommonExcption("提交扣罚申诉失败，稍后再试");
        }
        JSONObject result = JSONObject.parseObject(bas);
        if (!"0".equals(result.getString("code"))) {
            throw new CommonExcption(result.getString("msg"));
        }

    }

    /**
     * 根据条件，查询不同状态的扣罚申诉
     *
     * @param params 页面参数
     * @param u
     * @return
     */
    @Override
    public JSONObject queryAppealWithPage(Map<String, Object> params, UserEntity u) {

        try {
            //params.put("businessCode", "BUS_YT_ZZ");//业态code

            //客户名称或电话号码
            if (!StringUtils.isEmpty(params.get("customerInfo"))) {
                String customerNameOrPhone = params.get("customerInfo").toString();
                if (RegularUtil.verifyMatch(customerNameOrPhone, RegularUtil.REG_PHONE)) {
                    params.put("customerPhone", desUtil.encrypt(customerNameOrPhone));
                }
            }

            //进行查询
            String bas = HttpUtility.postJson(cmsNodeUrl + CmsNodeConstant.QUERY_APPEAL_WITH_PAGE, params);
            if (StringUtils.isEmpty(bas)) {
                throw new CommonExcption("查询扣罚申诉失败，请联系管理员");
            }
            //获取查询结果
            JSONObject jsonObject = JSONObject.parseObject(bas);
            if (!"0".equals(jsonObject.getString("code"))) {
                throw new CommonExcption("查询扣罚申诉失败，请联系管理员");
            }
            JSONObject data = jsonObject.getJSONObject("data");
            return data;
        } catch (CommonExcption e) {
            throw new CommonExcption(e.getMessage());
        } catch (Exception e) {
            throw new CommonExcption("查询扣罚申诉失败，请联系管理员");
        }

    }

    /**
     * 根据扣罚记录id，查询扣罚申诉,是将所有记录都进行返回
     *
     * @param id 扣罚记录id
     * @param appealId 当前申诉记录id
     */
    @Override
    public List<DeductionAppealDto> getAppealByPunishId(Long id, Long appealId) throws IOException {
        try {
            String bas = HttpUtility.getRest(cmsNodeUrl + CmsNodeConstant.GET_APPEAL_BY_PUNISH_ID + "?punishId=" + id, null);
            if (StringUtils.isEmpty(bas)) {
                throw new CommonExcption("查询扣罚申诉记录失败，请联系管理员");
            }
            //获取单条扣罚申诉记录
            JSONObject jsonObject = JSONObject.parseObject(bas);
            if (!"0".equals(jsonObject.getString("code"))) {
                throw new CommonExcption("查询扣罚申诉记录失败，请联系管理员");
            }
            if("[]".equals(jsonObject.getString("data"))){
                return null;
                //throw new CommonExcption("未查询到对应申诉记录，请刷新页面");
            }
            List<DeductionAppealDto> data = JsonUtil.json2List(jsonObject.getString("data"), DeductionAppealDto.class);

            //如果当前申诉id不为空，返回指定申诉记录记录
            if(!StringUtils.isEmpty(appealId)){
                //获取当前申诉记录
                for (int i = 0; i < data.size(); i++) {
                    DeductionAppealDto deductionAppealDto = data.get(i);
                    if(deductionAppealDto.getId().equals(appealId)){
                        ArrayList<DeductionAppealDto> list = new ArrayList<>();
                        list.add(deductionAppealDto);
                        return list;
                    }
                }
            }

            if(data == null || data.size() ==0){
                throw new CommonExcption("未查询到对应申诉记录，请刷新页面");
            }
            return data;
        } catch (CommonExcption e) {
            throw new CommonExcption(e.getMessage());
        } catch (Exception e) {
            throw new CommonExcption("查询扣罚申诉记录失败，请联系管理员");
        }
    }


    /**
     * 对扣罚申诉进行修改
     *
     * @param dto 扣罚申诉
     */
    @Override
    public void updateAppealById(UpdateDeductionAppealDto dto) throws IOException {

        //进行保存
        JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(dto));
        String bas = HttpUtility.postJson(cmsNodeUrl + CmsNodeConstant.UPDATE_APPEAL_BY_ID, jsonObject);
        if (StringUtils.isEmpty(bas)) {
            throw new CommonExcption("修改扣罚申诉失败，请稍后再试");
        }
        JSONObject result = JSONObject.parseObject(bas);
        if (!"0".equals(result.getString("code"))) {
            throw new CommonExcption(result.getString("msg"));
        }

    }

    /**
     * 扣罚申诉审核
     * @param map
     * @param user
     */
    @Override
    @Transactional
    public void deductionAppealReview(Map<String, Object> map, UserEntity user) throws IOException {

        //查询申诉记录
        List<DeductionAppealDto> list = getAppealByPunishId(Long.parseLong(map.get("id").toString()),Long.parseLong(map.get("appealId").toString()));
        DeductionAppealDto appealByPunishId = list.get(0);
        //当前登录是否是申诉人
        if (!user.getId().equals(appealByPunishId.getReviewerId())) {
            throw new CommonExcption("当前登录用户不是申诉审核人，不能进行审核");
        }

        //创建修改订单的参数
        UpdateDeductionAppealDto updateDto = new UpdateDeductionAppealDto();
        updateDto.setId(appealByPunishId.getId());//申诉id
        if("1".equals(map.get("type"))){
            updateDto.setState(3);//申诉状态：1：申诉审核中；2：申诉驳回；3：申诉成功；4：申诉撤销
            if(!StringUtils.isEmpty(map.get("deductionNumber"))){
                updateDto.setPoint(new BigDecimal(map.get("deductionNumber").toString()));// 申诉分数
            }else{
                if(null != appealByPunishId.getOldPoint()) {
                    updateDto.setPoint(appealByPunishId.getOldPoint());
                }else{
                    updateDto.setPoint(new BigDecimal(0));
                }
            }
            if(!StringUtils.isEmpty(map.get("deductionMoney"))){
                updateDto.setMoney(new BigDecimal(map.get("deductionMoney").toString()));// 申诉金额
            }else{
                if(null != appealByPunishId.getOldPoint()) {
                    updateDto.setMoney(appealByPunishId.getOldMoney());
                }else{
                    updateDto.setMoney(new BigDecimal(0));
                }
            }
        }else{
            updateDto.setState(2);
        }
        updateDto.setUserEntity(JSONObject.toJSONString(user));
        updateDto.setOverruleReason(String.valueOf(map.get("remark")));//审核说明

        //保存申诉记录
        updateAppealById(updateDto);

        //如果审核成功，发送信息提醒
        if("1".equals(map.get("type"))){
            cmsService.sendMessage(appealByPunishId.getFlowUserId(),user.getId(), new String[]{appealByPunishId.getFlowUserName(),appealByPunishId.getScProductOrderNo(),appealByPunishId.getNodeName()}, "FLSC_DEDUCTION_APPEAL_SUCESS", 1);
        }

    }
    /**
     * 继续进行扣罚申请
     * @param dto  申诉记录对象
     * @param remark   申诉理由
     * @param flowUser 审核用户
     * @param user  当前登录用户
     */
    @Override
    @Transactional
    public void continueAppeal(DeductionAppealDto dto, String remark, UserEntity flowUser, UserEntity user) throws IOException {

        //当前登录人是否是扣罚申诉人
        if (!user.getId().equals(dto.getFlowUserId())) {
            throw new CommonExcption("当前登录用户不是申诉人，不能继续进行申诉");
        }
        //创建修改订单的参数
        UpdateDeductionAppealDto updateDto = new UpdateDeductionAppealDto();
        updateDto.setId(dto.getId());//申诉id
        updateDto.setState(1);//申诉状态：1：申诉审核中；2：申诉驳回；3：申诉成功；4：申诉撤销
        updateDto.setUserEntity(JSONObject.toJSONString(user));
        updateDto.setReviewerId(flowUser.getId());//审核人id
        updateDto.setReviewerName(flowUser.getRealName());//审核人员名称
        updateDto.setAppealReason(remark);//申诉理由
        //保存申诉记录
        updateAppealById(updateDto);
    }


    /**
     * 查询扣罚记录，返回参数弹窗页面
     * @param id  扣罚id
     * @param appealId
     * @param user  当前登录用户
     * @param model  保存传递到页面的参数
     */
    @Override
    public void deductionAppealHtml(Long id, Long appealId, UserEntity user, Model model) throws IOException {
        TimeoutPunishDto timeoutPunishDto = this.queryTimeoutPunishById(id);
        if (timeoutPunishDto != null) {
//           // FlscProductOrder flscProductOrder = productOrderService.selectOrderByOrderNo(timeoutPunishDto.getOrderNo());
            ProductOrder productOrder = productOrderService.getProductOrderById(timeoutPunishDto.getProductOrderId());
          if (null != productOrder) {
              timeoutPunishDto.setBusinessName(productOrder.getBusinessTypeName());
                //隐藏电话
                String[] hideColum = {"customerPhone"};
              productOrder.setCustomerPhone(desUtil.decrypt(productOrder.getCustomerPhone()));
              productOrder = CustomerNumberEncryptionUtil.encryptionObject(hideColum, productOrder);

                model.addAttribute("customerName", productOrder.getCustomerName());//客户名称
                model.addAttribute("customerPhone", productOrder.getCustomerPhone());//客户电话
                model.addAttribute("orderNo", productOrder.getOrderNo());//生产订单主销售订单编号
            } else {
                //throw new CommonExcption("未查询到扣罚记录对应生产订单，请核对");
              model.addAttribute("customerName", timeoutPunishDto.getCustomerName());//客户名称
              model.addAttribute("customerPhone", net.dgg.iboss.base.util.StringUtils.encryptionNumber(desUtil.decrypt(timeoutPunishDto.getCustomerPhone())));//客户电话
              model.addAttribute("orderNo", timeoutPunishDto.getOrderNo());//生产订单主销售订单编号
            }
        }
        //查询生产订单
        model.addAttribute("order", timeoutPunishDto);
        //如果页面没有传递申诉id，表示是扣罚第一次进行申诉
        if(StringUtils.isEmpty(appealId)){
            Long orderId = DggKeyWorker.nextId();
            model.addAttribute("appealId", orderId);//生成申诉id
        }else{
            model.addAttribute("appealId", appealId);//申诉记录id
        }
        Map map = cmsService.findOrgParent(user.getOrgId(), "ORG_LEVEL_1");
        if (map != null) {
            model.addAttribute("orgId", map.get("id"));//当前事业部id
        }

    }

    /**
     * 分页查询申诉待审核
     * @param params  页面参数
     * @param u  当前登录用户
     * @param r
     */
    @Override
    public DataTableResponse appealWaitReview(Map<String, Object> params, UserEntity u, DataTableRequest r) {
        params.put("state", 1);//申诉状态：1：申诉审核中；2：申诉驳回；3：申诉成功；4：申诉撤销',
        params.put("reviewerIdOrFlowUserId",u.getId());//审核人或申请人是当前登录人
        //查询申诉待审核订单
        JSONObject json = this.queryAppealWithPage(params,u);
        List<DeductionAppealDto> list = JsonUtil.json2List(json.getString("data"), DeductionAppealDto.class);
        if (list != null && list.size() > 0) {
            String[] hideColum = {"customerPhone"};
            list = desUtil.decryptList(hideColum, list);
            list = CustomerNumberEncryptionUtil.encryptionList(hideColum, list);
        }
        Integer count = json.getInteger("recordsTotal");
        return new DataTableResponse(r.getDraw(), count, count,list, "");
    }

    /**
     * 分页查询已完成申诉
     * @param params  页面参数
     * @param u  当前登录用户
     * @param r
     */
    @Override
    public DataTableResponse appealAlready(Map<String, Object> params, UserEntity u, DataTableRequest r) {
        params.put("state", 3);//申诉状态：1：申诉审核中；2：申诉驳回；3：申诉成功；4：申诉撤销',
        params.put("reviewerIdOrFlowUserId",u.getId());//审核人或申请人是当前登录人
        //查询已完成申诉订单
        JSONObject json = this.queryAppealWithPage(params, u);
        List<DeductionAppealDto> list = JsonUtil.json2List(json.getString("data"), DeductionAppealDto.class);
        if (list != null && list.size() > 0) {
            String[] hideColum = {"customerPhone"};
            list = desUtil.decryptList(hideColum, list);
            list = CustomerNumberEncryptionUtil.encryptionList(hideColum, list);
        }
        Integer count = json.getInteger("recordsTotal");
        return new DataTableResponse(r.getDraw(), count, count, list, "");
    }

    /**
     * 分页查询申诉驳回记录
     * @param params  页面参数
     * @param u  当前登录用户
     * @param r
     */
    @Override
    public DataTableResponse appealReject(Map<String, Object> params, UserEntity u, DataTableRequest r) {
        params.put("state", 2);//申诉状态：1：申诉审核中；2：申诉驳回；3：申诉成功；4：申诉撤销',
        params.put("flowUserId",u.getId());//申诉驳回记录流程人员是当前登录用户
        //查询申诉驳回订单
        JSONObject json = this.queryAppealWithPage(params, u);
        List<DeductionAppealDto> list = JsonUtil.json2List(json.getString("data"), DeductionAppealDto.class);
        if (list != null && list.size() > 0) {
            String[] hideColum = {"customerPhone"};
            list = desUtil.decryptList(hideColum, list);
            list = CustomerNumberEncryptionUtil.encryptionList(hideColum, list);
        }
        Integer count = json.getInteger("recordsTotal");
        return new DataTableResponse(r.getDraw(), count, count, list, "");
    }

    @Override
    public List<DeductionAppealDto> getAppealRecord(Long id) throws IOException {
        try {
            String bas = HttpUtility.getRest(cmsNodeUrl + CmsNodeConstant.GET_APPEAL_BY_PUNISH_ID + "?punishId=" + id, null);
            if (StringUtils.isEmpty(bas)) {
                throw new CommonExcption("查询扣罚申诉记录失败，请联系管理员");
            }
            //获取单条扣罚申诉记录
            JSONObject jsonObject = JSONObject.parseObject(bas);
            if (!"0".equals(jsonObject.getString("code"))) {
                throw new CommonExcption("查询扣罚申诉记录失败，请联系管理员");
            }

            List<DeductionAppealDto> data = JsonUtil.json2List(jsonObject.getString("data"), DeductionAppealDto.class);
            return data;
        } catch (CommonExcption e) {
            throw new CommonExcption(e.getMessage());
        } catch (Exception e) {
            throw new CommonExcption("查询扣罚申诉记录失败，请联系管理员");
        }
    }


    /**
     * 撤回扣罚申诉
     *  @param id 扣罚申诉id
     * @param appealId
     * @param u
     */
    @Override
    @Transactional
    public void withdrawAppeal(Long id, Long appealId, UserEntity u) throws IOException {

        //查询申诉记录
        List<DeductionAppealDto> list = getAppealByPunishId(id,appealId);
        DeductionAppealDto appealByPunishId = list.get(0);
        //当前登录是否是申诉人
        if (!u.getId().equals(appealByPunishId.getFlowUserId())) {
            throw new CommonExcption("当前登录用户不是扣罚申诉人，不能进行撤回");
        }

        //创建修改订单的参数
        UpdateDeductionAppealDto updateDto = new UpdateDeductionAppealDto();
        updateDto.setId(appealByPunishId.getId());//申诉id
        updateDto.setState(4);//申诉状态：1：申诉审核中；2：申诉驳回；3：申诉成功；4：申诉撤销
        updateDto.setUserEntity(JSONObject.toJSONString(u));
        //保存申诉记录
        updateAppealById(updateDto);

    }
    /**
     * 根据申诉记录id从扣罚申诉记录集合中，获取单条申诉记录
     *
     * @param data     申诉记录集合
     * @param appealId 当前申诉记录id
     */
    public DeductionAppealDto getAppealById(List<DeductionAppealDto> data, Long appealId) throws IOException {

        //集合为空返回null
        if (data == null || data.size() == 0) {
            return null;
        }

        //申诉记录id为空，返回null
        if (StringUtils.isEmpty(appealId)) {
            return null;
        }
        //获取当前申诉记录
        for (int i = 0; i < data.size(); i++) {
            DeductionAppealDto deductionAppealDto = data.get(i);
            if (deductionAppealDto.getId().equals(appealId)) {
                return deductionAppealDto;
            }
        }
        return null;

    }


}

